Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle arguments more strictly #5340

Merged
merged 1 commit into from
Mar 4, 2024
Merged

Conversation

TheodoreEhrenborg
Copy link
Contributor

Category:

Refactoring (Redesign of existing code that doesn't affect functionality)

Description:

This code looks like it validates that the auto_reset argument is True, False, "yes", "no", or None:

        if not auto_reset or auto_reset is None or auto_reset == "no":
            self._auto_reset = "no"
        elif auto_reset or auto_reset == "yes":
            self._auto_reset = "yes"
        else:
            raise ValueError(f"Unsupported value for `auto_reset` {auto_reset}")

But in fact the else clause will never trigger, because all falsy values will trigger the first branch, and all truthy values (except "no") will trigger the second branch. So the else clause is dead code.

And if the user provides "False" or "No", the code will silently set self._auto_reset to "yes"

This PR limits acceptable values to True, False, "yes", "no", or None

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Signed-off-by: Theodore Ehrenborg <theodore.ehrenborg@gmail.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [13173163]: BUILD STARTED

@JanuszL
Copy link
Contributor

JanuszL commented Feb 29, 2024

Hi @TheodoreEhrenborg,

Nice catch. Thank you for our PR.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [13173163]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [13173163]: BUILD PASSED

@mzient mzient merged commit 029c2bf into NVIDIA:main Mar 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants